﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_TBcompayCount : System.Web.UI.Page, HZ.MBSM.BLL.IPageDescribe
{
    public string BId;
    protected void Page_Load(object sender, EventArgs e)
    {

        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumBidGoods);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];

            if (_Account != null)
            {
                Int64 AccountId = SysFun.ToLong(_Account.AccountId);
                if (!IsPostBack)
                {
                    Db db = new Db();
                    string strSql = "select projectid,ProjectMarker,Title from project where accountid in (select accountid_father from dbo.AgencyChild where accountid=" + AccountId.ToString() + ")";
                    System.Data.IDataReader dr = db.DataReader(strSql);
                    listProject.DataSource = dr;
                    listProject.DataTextField = "Title";
                    listProject.DataValueField = "projectid";
                    listProject.DataBind();
                    dr.Close();
                    dr.Dispose();
                    string projectid = listProject.SelectedValue;

                    strSql = "select distinct AccountId_TB, salername from bidgoods_view where projectid=" + projectid + " order by salername";
                    dr = db.DataReader(strSql);
                    Company.DataSource = dr;
                    Company.DataTextField = "salername";
                    Company.DataValueField = "AccountId_TB";
                    Company.DataBind();
                    Company.Items.Insert(0, new ListItem("全部", "-1"));
                    dr.Close();
                    dr.Dispose();
                    db.Close();
                    lstCheckStatus.Items.Add("全部");
                    lstCheckStatus.Items.Add("未审核");
                    lstCheckStatus.Items.Add("审核通过");
                    lstCheckStatus.Items.Add("审核未通过");
                    Company.SelectedValue = "";
                  
                   
                    Session["IsCheck"] = "1";

                }
                if (Request.Form["chk"] != null)
                {
                    string _strBidId = Request.Form["chk"].ToString(), _strSub, strSql;
                    _strSub = Request.Form["subPass"];
                    BId = Request.Form["chk"].ToString();
                    if (_strSub == "" || _strSub == null)
                    {
                        _strSub = Request.Form["subNoPass"];
                    }
                    Db db1 = new Db();
                    string atname = _Account.AccountName;
                    //string attype = _Account.Type;
                    if (_strSub == "审核通过")
                    {
                        strSql = "update project_bid set checkstatus=1,memo8='" + atname + "',SHSJ=getdate(),memo9=null where bidid in (" + _strBidId + ")";
                        db1.Command(strSql);
                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "project_bid", strSql, "../Agency/Check_BidGood_Child.aspx");

                    }
                    else if ((_strSub == "审核不通过") && (Session["IsCheck"].ToString() == "1"))
                    {
                        Response.Write("<Script>window.open('BidNoPass.aspx?Bidid=" + BId + "')</Script>");
                    }

                    db1.Close();
                }
                Session["IsCheck"] = "1";
                showGridView();
            }
        }
    }

    public void showGridView()
    {
        int i = 0;
        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "bidgoods_view";                                               //要查询的表明
        dbPage.Key = "bidid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "usercode_tb,salername, max(company_sc_check) as Company_SC_check , count(bidid) as bidnb,sum(case checkstatus when 1 then 1 else 0 end ) as pass, sum(case checkstatus when 0 then 1  when null then 1 else 0 end ) as nochecks,sum(case checkstatus when 0 then 0  when null then 0 when 1 then 0 else 1 end ) as nopass  ";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数
   
        dbPage.OrderBy = "usercode_tb";//排序字段
        dbPage.SelectFieldGroup = "usercode_tb,salername";
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='center' cellpadding='2' cellspacing='1'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td class='table_title' nowrap>注册号</td>");
        strHtml.Append("<td class='table_title' nowrap>投标人</td>");
     ;
        strHtml.Append("<td class='table_title' nowrap>投标数</td>");
        strHtml.Append("<td class='table_title' nowrap>已审核数</td>");
        strHtml.Append("<td class='table_title' nowrap>不通过数</td>");
        strHtml.Append("<td class='table_title' nowrap>未审核数</td>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReaderGroup(40);

        while (dr.Read())
        {
           
            strHtml.Append("<td>" + dr["UserCode_TB"].ToString() + "</td>");
            if ((dr["Company_SC_check"].ToString()== "") || (dr["Company_SC_check"].ToString()=="0"))
            {
                strHtml.Append("<td title='未审核' >" + dr["salername"].ToString() + "</td>");
            }
            else if (dr["Company_SC_check"].ToString() == "2")
            {
                strHtml.Append("<td title='审核不通过' style=' color: #ff0033;'>" + dr["salername"].ToString() + "</td>");
            }
            else
            {
                strHtml.Append("<td title='审核通过' style=' color: #00cc66;' >" + dr["salername"].ToString() + "</td>");
            }
            strHtml.Append("<td>" + dr["bidnb"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["pass"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["nopass"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["nochecks"].ToString() + "</td>");
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Label1.Text = strHtml.ToString();

        //GridView1.DataSource = dr;
        //GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "", company, projectid, CompanyUserCode, CheckStatus;
        CompanyUserCode = txtCompanyUserCode.Text.Trim();
        company = SysFun.ToTrim(Company.SelectedValue);
        projectid = listProject.SelectedValue;
        strtemp = " projectid=" + projectid + " and";

        CheckStatus = lstCheckStatus.SelectedValue;
        switch (CheckStatus)
        {
            case "全部":
               
                break;
            case "未审核":
                strtemp += " (company_sc_check=0 or company_sc_check is null)  and";
                break;
            case "审核通过":
                strtemp += " company_sc_check=1 and";
                break;
            case "审核未通过":
                strtemp += " company_sc_check=2 and";
               
                break;
        }
        if (company != "-1")
        {
            strtemp = strtemp + " accountid_tb='" + company + "' and";
        }
        if (CompanyUserCode != "")
        {
            strtemp += " UserCode_TB='" + CompanyUserCode + "' and";
        }

        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }






    #region IPageDescribe 成员

    public string Name
    {
        get { return "投标企业统计"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "投标企业统计"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumBidGoods);
            return _AccountType;
        }
    }
    #endregion
    protected void Button5_Click(object sender, EventArgs e)
    {

    }
}